using System;
using System.Data;
using Utils;
using Utils.DatabaseUtils;
using System.Data.SqlClient;


namespace DCEdu
{
public class Account
{ 
	private int iD;
	public int ID
	{
		get { return iD;}
		set { iD = value;}
	}

	private String username;
	public String Username
	{
		get { return username;}
		set { username = value;}
	}

	private String password;
	public String Password
	{
		get { return password;}
		set { password = value;}
	}

	public Account() {}

	public Account(int iD, String username, String password)
	 {
		this.iD = iD;
 		this.username = username;
 		this.password = password;
 	}

	public int Add(String username, String password)
	{
		try
		{
			int result = SqlHelper.ExecuteNonQuery(Common.Conn,"Account_Add",username,password);
			return result;
		}
		catch(Exception e) {return -1; }
	}

	public int Update(String username, String password)
	{
		try
		{
            int result = SqlHelper.ExecuteNonQuery(Common.Conn, "Account_Update", username, password);
			return result;
		}
		catch(Exception e) {return -1; }
	}

	public int Delete(int iD)
	{
		try
		{
			int result = SqlHelper.ExecuteNonQuery(Common.Conn,"Account_Delete",iD);
			return result;
		}
		catch(Exception e) {return -1; }
	}

	public int DeleteAll()
	{
		try
		{
			int result = SqlHelper.ExecuteNonQuery(Common.Conn,"Account_DeleteAll");
			return result;
		}
		catch(Exception e) {return -1; }
	}

	public DataSet Get(int iD)
	{
		try
		{
			DataSet result = SqlHelper.ExecuteDataset(Common.Conn,"Account_Get",iD);
			return result;
		}
		catch(Exception e) {return null; }
	}

	public DataSet GetAll()
	{
		try
		{
			DataSet result = SqlHelper.ExecuteDataset(Common.Conn,"Account_GetAll");
			return result;
		}
		catch(Exception e) {return null; }
	}

    public int checkLogin(String username, String password)
    {
        try
        {
            int result = Convert.ToInt32(SqlHelper.ExecuteScalar(Common.Conn, "Account_Login", username, password));
            return result;
        }
        catch (Exception e) { return -1; }
    }

    public int checkPass(String password)
    {
        try
        {
            int result = Convert.ToInt32(SqlHelper.ExecuteScalar(Common.Conn, "Account_CHECKPASS", password));
            return result;
        }
        catch (Exception e) { return -1; }
    }
} 
}
